package com.totoro.utils;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Getter;
import lombok.Setter;
import lombok.SneakyThrows;

import java.io.Serializable;

/**
 * @author TOTORO
 */
@Setter
@Getter
public class OutputJson implements Serializable {
    /**
     * 返回客户端统一格式，包括状态码，提示信息，以及业务数据
     */
    private static final long serialVersionUID = 1L;
    /** 状态码 */
    private int code;
    /** 必要的提示信息 */
    private String msg;
    /** 业务数据 */
    private Object data;
    private boolean isSuccess;

    public OutputJson(int code,String msg){
        this.code = code;
        this.msg = msg;
    }
    @SneakyThrows
    @Override
    public String toString(){
        return new ObjectMapper().writeValueAsString(this);
    }
}
